package gae.colopl;

import gae.colopl.bean.User;
import gae.colopl.http.ColoplLoginException;
import gae.colopl.http.ColoplRequestException;
import gae.colopl.http.ColoplRequestManager;
import gae.colopl.http.bean.ItemWHData;
import gae.colopl.http.bean.LinkColony;
import gae.colopl.http.user.Session;

import java.util.ArrayList;
import java.util.List;

public class ColoplServiceImpl extends AbstractColoplService {
    
    //private static ColoplRequestManager manager = ColoplRequestManager.getInstance();
    
    
    public ColoplServiceImpl() {
    }
    
    @Override
    public User getUserInfo(String username, String password) throws ColoplRequestException, ColoplLoginException {
        
        Session userSession = manager.requestLogin(username, password);
        
        User userInfo = new User();
        userInfo.setUsername(username);
        userInfo.setPassword(password);
        userInfo.setId(userSession.getId());
        userInfo.setUid(userSession.getUid());
        
        return userInfo;
    }
    
    @Override
    protected List<ItemWHData> getWHItems(String username, String password)
            throws ColoplRequestException {
        
        List<ItemWHData> data = new ArrayList<ItemWHData>();
        ItemWHData wh = manager.requestItemWH(username, password, 0);
        int pageSize = Integer.valueOf(wh.getPageCount());
        for (int i = 0; i < pageSize; i++) {
            if (i != 0) {
                wh = manager.requestItemWH(username, password, i);
            }
            data.add(wh);
        }
        
        return data;
    }

    @Override
    protected List<LinkColony> getNearLinkColonies(String username,
            String password) throws ColoplRequestException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected List<LinkColony> getFarLinkColonies(String username,
            String password) throws ColoplRequestException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected List<LinkColony> getFriendLinkColonies(String username,
            String password) throws ColoplRequestException {
        // TODO Auto-generated method stub
        return null;
    }

}
